package org.restoran.model;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

/**
 * Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as a base class for objects
 * needing these properties.
 *
 * @author Snisar Bogdan.
 */
@MappedSuperclass
public abstract class NameEntity extends BaseEntity {
    protected NameEntity(Integer id, String name) {
        super(id);
        this.name = name;
    }

    protected NameEntity(String name) {
        this.name = name;
    }

    protected NameEntity(Integer id) {
        super(id);
    }

    public NameEntity() { }

    @Column(name = "name")
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "id=" + super.getId() + ", name=" + this.getName();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof NameEntity)) return false;

        NameEntity that = (NameEntity) o;

        if (name != null ? !name.equals(that.name) : that.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return name != null ? name.hashCode() : 0;
    }
}
